<template>
	<!-- 务农管理 -->
  <div class="stu">
	 <el-dialog v-loading="loading"  :title="num==1?'编辑app版本信息':'新增app版本信息'" :visible.sync="dialogVisible" width="650px" :before-close="handleClose"  :close-on-click-modal='false'>
	   <!-- <p class="pbox" style="text-align: center;width:100%;font-size:30px;height:40px;">员工信息详情</p> -->

	    <div style="width:100%;margin: 0 auto;padding-bottom:20px;">
			
			<div style="margin-top:10px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;">* </a>版本名</p>
					<el-input style='width:75%;'   placeholder="请输入" v-model="activess.version_name" clearable></el-input>
			</div>
			<div style="margin-top:10px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;">* </a>版本号</p>
					<el-input style='width:75%;'   placeholder="请输入" v-model="activess.version_number" clearable></el-input>
			</div>
			<div style="margin-top:10px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;">* </a>app类型</p>
					<el-select style="width:75%;border:none;" class="pboxc1" v-model="activess.app_type" clearable filterable placeholder="请选择">
					   <el-option :label="'Android'" :value="'1'"></el-option>
					   <el-option :label="'IOS'" :value="'2'"></el-option>
						 <el-option :label="'一体机'" :value="'3'"></el-option>
					</el-select>
			</div>
			<div style="margin-top:10px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;">* </a>app下载地址</p>
					<el-input style='width:58%;' disabled placeholder="" v-model="activess.app_url" clearable>
						 <template slot="append">URL</template>
					</el-input>
					<el-button class='topbtn' @click='update' type="success" style='padding:10px 10px;margin-left:10px;'>上传安装包</el-button>
					<input @change="handleFile" type="file" id="excel-file" style="BACKGROUND-COLOR: transparent;opacity:0;display: none;">
			</div>
			<div style="margin-top:10px;height:200px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;"> </a>更新内容</p>
					<el-input style='width:75%;' type="textarea" :rows="10" class='tabinp' v-model="activess.content" placeholder="请输入" clearable></el-input>
			</div>
		</div>	
		<div style="width:100%;height:40px;margin-top:20px;">
	      <div style="width:170px;margin: 0 auto;">
	        <el-button type="danger" @click="handleClose">取 消</el-button>
	        <el-button type="primary" style='float:right;' @click="git_acts">确 定</el-button>
	      </div>
		</div>
	 </el-dialog>
	
  </div>
</template>

<script>
import $ from 'jquery'
export default {
  name: 'stu',
  components: {},//声明子组件
  computed:{
	 
  },
  data(){
	  return {
		loading:false,
		btn_shou:false,
		dialogVisible: false,
		activess:{
				      version_name:'',//版本名
				      version_number:'',//版本号
				  	  app_type:'',//app类型  1Android  2ios
				  	  app_url:'',//app下载地址
				  	  id:'',//主键
					  content:'',
		},
		jt:[],
		ry:[],
		renbox:[],
		num:0,
	  }
  },
  methods:{
	  update(){//
	    if(this.isNull(this.activess.app_type)){this.$message.error('请选择 app类型');return false}
	  	document.querySelector("#excel-file").click();//事件委托
	  },
	  handleFile(e){//上传文件
	        
	        const loading = this.$loading({//显示加载中
	                  lock: true,
	                  text: '文件上传中，请稍后...',
	                  spinner: 'el-icon-loading',
	                  background: 'rgba(0, 0, 0, 0.7)'
	        });
	        
	         let fil = e.target.files[0];
	         var formData = new FormData();
	         formData.append("app_file",fil);
			 formData.append("app_type",this.activess.app_type);
	         $('#excel-file').val('');//实现可以上传同一个文件
	  			     $.ajax({
	  			       url:'/dj/convent_service/index',
	  			       type: 'post',// 设置的是请求参数
	  			        data: formData,
	  			        contentType: false,
	  			        processData: false,
	  			       dataType: 'json',
	  			       success: (res)=> {
	  					 if(Object.prototype.toString.call(res) != '[object Object]'){res = JSON.parse(res)}
	  					 if(res.code==200){
						  console.log(res)
	  					  this.$message({type: 'success',message: '上传成功!'});
	  			          this.activess.app_url = res.data;
	  					 }else{this.$message.error(res.msg);loading.close();}
						 loading.close();//关闭加载中
	  			       }
	  			     })
	  },
	  git_act(i,num){//获取数据的同打开狂口
	      if(num==1){
			  this.activess = i;
			  console.log(this.activess);
			  // this.activess.poor_rid_id = Number(this.activess.poor_rid_id);
			  this.activess.app_type = this.activess.app_type+'';
			  // this.git_jia(true);
		  }
		  this.num = num;
	      // console.log(this.activess,num);
	      this.dialogVisible=true;
	  },
	  git_acts(){//提交数据
	        console.log(this.activess)
	        if(this.isNull(this.activess.version_name)){this.$message.error('请输入 版本名');return false}
			if(this.isNull(this.activess.version_number)){this.$message.error('请输入 版本号');return false}
			if(this.isNull(this.activess.app_type)){this.$message.error('请选择 app类型');return false}
	  		if(this.isNull(this.activess.app_url)){this.$message.error('请上传app安装包');return false}
			if(this.isNull(this.activess.content)){this.$message.error('请输入 更新内容');return false}
	  		 let url = this.num==1?'/dj/user_manage/app_version_modify':'/dj/user_manage/app_version_insert';
	  		 $.ajax({url:url,type:'post',data:this.activess,dataType:'json',success:(res)=> {
	  		 	if(Object.prototype.toString.call(res) != '[object Object]'){res = JSON.parse(res)}
	  		 	 console.log(res,'提交');
	  		 	 if(res.code==200){
	  				this.$parent.git_act();
	  		 		this.$message({message: '操作成功',type: 'success'});
	  		 		this.dialogVisible=false;
	  				this.qin();
	  		 	  }else{
	  		 		 this.$message.error(res.msg);
	  		 	  }
	  		 	}
	  		 })
	  },
	  qin(){//清除
	  	this.activess={
				      version_name:'',//版本名
				      version_number:'',//版本号
				  	  app_type:'',//app类型  1Android  2ios
				  	  app_url:'',//app下载地址
				  	  id:'',//主键
					  content:'',
		}
	  },
	  
	  handleClose(done){//监测用户点击x
	     this.$confirm('确定取消关闭吗？','提示',{confirmButtonText:'确定',cancelButtonText:'取消',type: 'warning'
	     }).then(() => {
	  	   this.dialogVisible = false;
	  	   this.qin();
		   this.$parent.git_act();
	  	}).catch(() => {});
	  },
	  
  },
  mounted(){
	  // this.git_ren()
  }
}
</script>
<style scoped="scoped">
	
	.pboxc1{
		float:left;
		width:70%;
		height:40px;
		border:1px solid rgba(242,242,242,1);
		font-size:14px;color:#666666;
		/* padding-left:18px; */
		text-align:left;
		/* overflow: hidden; */
		/* text-overflow:ellipsis; */
		/* white-space: nowrap; */
	}
	.tabbox{
		width:100%;
		height:40px;
		line-height: 30px;
		margin-top:23px;
	}
	.tabbox p{
		font-size:14px;
		color:#000000;
		width:19.5%;
		text-align:right;
		margin-right:28px;
		float:left;
		overflow: hidden;
		text-overflow:ellipsis;
		white-space: nowrap;
		font-family:Source Han Sans CN;
	}
	.pbox{
		width:10%;
		text-align:right;
		height:26px;
		margin-bottom:20px;
		font-size:18px;
		color:#000101;
		overflow: hidden;
		text-overflow:ellipsis;
		white-space: nowrap;
		font-family:Source Han Sans CN;
		font-weight:600;
	}
</style>
